package springbootorderrabbitmqproducer.demo.config;

import org.springframework.amqp.core.*;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.*;

import java.util.*;

/**
 * @ClassName HeadsMqConfiguration
 * @Date 2021/6/8 0008 上午 10:33
 * @Author Administrator
 * @Description TODO
 * Version 1.0
 */
@Configuration
public class HeadsMqConfiguration {

    String exchangeName = "headers_play_exchange";
    String smsHeadersQueueName = "sms";
    String weChatHeadersQueueName = "weChat";
    String emailHeadersQueueName = "email";

    @Bean
    public HeadersExchange headersExchange() {
        return new HeadersExchange(exchangeName, true, false);
    }

    @Bean
    public Queue smsHeadersQueue() {
        return new Queue(smsHeadersQueueName, true);
    }

    @Bean
    public Queue weChatHeadersQueue() {
        return new Queue(weChatHeadersQueueName, true);
    }

    @Bean
    public Queue emailHeadersQueue() {
        return new Queue(emailHeadersQueueName, true);
    }

    @Bean
    public Binding smsHeadersBinding(){
        Map<String,Object> map = new HashMap<>();
        map.put("queueName","sms");
        map.put("name","敦佳星");
        map.put("age","20");
        map.put("sex","男");
        return BindingBuilder.bind(smsHeadersQueue()).to(headersExchange()).whereAny(map).match();
    }
    @Bean
    public Binding weChatHeadersBinding(){
        Map<String,Object> map = new HashMap<>();
        map.put("queueName","weChat");
        map.put("name","刘荣华");
        map.put("age","19");
        map.put("sex","女");
        return BindingBuilder.bind(weChatHeadersQueue()).to(headersExchange()).whereAny(map).match();
    }
    @Bean
    public Binding emailHeadersBinding(){
        Map<String,Object> map = new HashMap<>();
        map.put("queueName","email");
        map.put("name","李熙蕾");
        map.put("age","20");
        map.put("sex","女");
        return BindingBuilder.bind(emailHeadersQueue()).to(headersExchange()).whereAny(map).match();
    }
}
